package com.ztjy.market.controller;

import com.github.pagehelper.PageInfo;
import com.ztjy.bean.Custom;
import com.ztjy.bean.Users;
import com.ztjy.market.biz.CustomBiz;
import com.ztjy.sys.biz.AreaBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/market/customerBrowse")
public class CustomerBrowseController {
    @Autowired
    private CustomBiz ubiz;
    @Autowired
    private AreaBiz abiz;

    @RequestMapping("/ulist")
    public String all(Model model, Custom custom, HttpSession session,@RequestParam(value = "pageno",defaultValue = "1")Integer pageNo){
        Integer pageSize=6;

        Users users = (Users) session.getAttribute("currUser");
        if(users.getJobId()==3 || users.getJobId()==3){//组长 组员
            custom.setServiceid(users.getuId());
        }

        PageInfo<Custom> customPage = ubiz.findCustomPage(custom, pageNo, pageSize);
        model.addAttribute("upage",customPage);
        model.addAttribute("custom",custom);
        System.out.println("custom = " + custom);
        return "forward:/market/customerBrowse/customerBrowse.html";
    }

    @RequestMapping("/find/{id}")
    public String details(@PathVariable("id")Integer customid, HttpServletRequest request){
        Custom byIdCustom = ubiz.findByIdCustom(customid);
        request.setAttribute("custom",byIdCustom);
        return "forward://market/customer/customerView.html";
    }
}
